<template>
  <div class="login_container">
    <el-collapse-transition  class="elcotr">
      <div v-show="loadShow" style="height: 100%">
        <div class="loading">
        </div>
      </div>
    </el-collapse-transition>
<!--    页面布局-->
    <el-container class="home-container">
      <el-header>
        <div class="home_img">
           <img src="../../assets/image/home_tag.png">
            <span>电商后台管理系统</span>
        </div>
        <el-button type="info" @click="layout">退出登入</el-button>
      </el-header>

      <el-container>
<!--        侧边栏-->
        <el-aside :width="isCollapse ? '70px' : '200px'">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
<!--          菜单栏-->
          <el-menu
              background-color="rgba(243, 106, 106, 0.2)"
              text-color=" rgba(98, 241, 236, 1)"
              active-text-color="#ffd04b" unique-opened :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath" >
<!--            一级菜单-->
            <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id"  >
              <template slot="title">
                <i :class="iconsObj[item.id]" ></i>
                <span>{{item.authName}}</span>
              </template>
<!--              二级菜单-->
              <el-menu-item :index="'/'+chItem.path" v-for="chItem in item.children" :key="chItem.id" @click="saveNavState('/'+chItem.path,{itemPath:item.authName,chitemPah:chItem.authName})">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{chItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>

          </el-menu>
        </el-aside>
        <el-main>
           <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  data(){
    return{
       loadShow:true,
       menuList:[],
       iconsObj:{
          '125':'el-icon-s-check',
          '103':'el-icon-s-tools',
          '101':'el-icon-s-goods',
          '102':'el-icon-s-order',
          '145':'el-icon-s-management'
       },
      isCollapse:false,
      //被激活的链接地址
      activePath:'',
    }
  },
  mounted() {
    this.loadShow=false;
  },
  created() {
    this.getMenuList();
    this.activePath=window.sessionStorage.getItem("activePath");
  },
  methods:{
    layout(){
      window.sessionStorage.clear();
      this.$router.push('/login')
    },
    //请求获取菜单列表
    async getMenuList(){
      try {
        const { data: res }=await this.axios.get("menus");
        if (res.meta.status!==200){
         return  this.$message.error(res.meta.msg);
        }
        this.menuList=res.data
       }catch (e) {
           this.$message.error("服务器出错请联系管理员")
      }
    },
    toggleCollapse(){
      this.isCollapse=!this.isCollapse;
    },

    saveNavState(path,val){
      //保存当前路由path到sessionStorage
      window.sessionStorage.setItem("activePath",path);
      //保存当前pathName到sessionStorage,以便面包屑组件的复用
      window.sessionStorage.setItem("pathName",JSON.stringify(val));
    },
  },

}
</script>

<style lang="less" scoped>
.home-container{
  height: 100%;
}
.login_container {
  /* 设置 z-index 来确保背景位于上方 */
  background-image: url("../../assets/image/bghome2.jpg");
  background-size: cover; /* 根据容器大小缩放背景图片 */
  background-position: center; /* 将背景图片居中 */
  background-repeat: no-repeat; /* 禁止背景图片重复 */
  height: 100% ;
  overflow: auto; /* 当内容溢出容器时允许滚动 */

}
.loading{
  height: 100% ;
  background-image: url("../../assets/image/bg.jpg");
  background-size: cover; /* 根据容器大小缩放背景图片 */
  background-position: center; /* 将背景图片居中 */
  background-repeat: no-repeat; /* 禁止背景图片重复 */
}

.el-header{
  display: flex;
  justify-content: space-between;
  padding-right: 10px;
  padding-left: 10px;
  align-items: center;
  color: rgba(98, 231, 236, 0.8);
  font-size: 30px;
  >div{
    display: flex;
    align-items: center;

  }
  border: 2px solid rgba(77, 105, 243, 0.5); /* 设置边框宽度、颜色和样式 */
  background-color: rgba(243, 106, 106, 0.2);
}

.el-aside {
  background-color: rgba(248, 188, 188, 0.2);
  .el-menu{
    border-right: none;
  }
}
.el-menu--collapse {
  width: 100%;
}

.el-main {
  background-color: rgba(0, 0, 0, 0.2);
}
.home_img{
  height: 100%;
  width: 100%;
  img{
    height: 100%;
    margin-right: 10px;
  }
}
span{
  margin-left: 10px;
}
.toggle-button{
  background-color: rgba(253, 102, 102, 0.4);
  font-size: 10px;
  line-height: 25px;
  color: rgba(98, 231, 236, 0.8);
  font-weight: bold;
  text-align: center;
  letter-spacing: 0.2em;
  cursor:pointer;
}


///deep/ .el-menu-item-group__title{
//  background-color: rgba(184, 83, 83, 0.5);
//  color: #222222;
//}

</style>
